package com.example.security.demo.service.impl;

import com.example.security.demo.entity.SysUser;
import com.example.security.demo.mapper.SysUserMapper;
import com.example.security.demo.service.UserService;
import com.example.security.demo.vo.UserVo;
import lombok.AllArgsConstructor;
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
import org.springframework.stereotype.Service;

/**
 * @author zhanpengguo
 * @date 2019-10-15 13:39
 */
@Service
@AllArgsConstructor
public class UserServiceImpl implements UserService {

    private final BCryptPasswordEncoder bCryptPasswordEncoder;

    private final SysUserMapper sysUserMapper;

    @Override
    public void save(UserVo userVo) {
        SysUser sysUser = new SysUser();
        sysUser.setUsername(userVo.getUsername());
        sysUser.setPassword(bCryptPasswordEncoder.encode(userVo.getPassword()));
        sysUserMapper.insert(sysUser);
    }
}
